package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;

public class Menu {

    private ArrayList<Option> options;

    public Menu()
    {
        options = new ArrayList<Option>();
        options.add(new Option("Browse Available Books\n"));
        options.add(new Option("Reserve A Book\n"));
        options.add(new Option("List Movies\n"));
        options.add(new Option("Check Membership\n"));
        options.add(new Option("Quit"));
    }

    public String getMenu()
    {

        String menu = "===Menu===\n";
        int i = 1;
        for(Option option : options) {
            menu = menu.concat(String.valueOf(i) + ". ");
            menu = menu.concat(option.title);

            i++;
        }
        return menu;

    }
    public boolean isValidOption(int selection)
    {
        return !(selection < 0 || selection > options.size());
    }

    public String selectOption(BookList books, BufferedReader br, MovieList movieList) throws IOException {

        int option = Integer.parseInt(br.readLine());
        String message = "Select a Valid Input!";
        if(option == 1)
        {
            return books.Reservable();
        } else {
            if (option == 2) {
                int input;
                System.out.print("Enter a number associated with the book you want to reserve.\n");
                try {
                    input = Integer.parseInt(br.readLine());
                } catch (NumberFormatException e) {
                    return "Reservation Failed!";
                }
                if(! books.isReservable(input))
                    return "AHH not reservable!";
                books.Reserve(input);
                return "Reserve Successful!";
            }
            else if (option == 3) {
                return movieList.getMovieList();
            }
            else if (option == 4) {
                return "Please talk to a Librarian. Thank you.";
            }
            else    if (option == 5) {
                return "Quit";
            }
            return message;
        }
    }

}